
<%@page import="com.rainliang.project.util.CookieUtil"%>
<%@page import="com.rainliang.project.connect.util.QQ_Util"%>
<%@ page contentType="text/html;charset=utf-8" %>
<%@page import="java.util.Map"%>
<%@page import="org.apache.commons.logging.LogFactory"%>
<%@page import="org.apache.commons.logging.Log"%>
<%
Log logger = LogFactory.getLog(this.getClass());
	String authorization_Code=request.getParameter("code");
	
	if(authorization_Code==null||authorization_Code.equals("")){
		logger.warn("get renren authorization_Code error! is null ");
%>
		<script type="text/javascript">
		alert('QQ登录连接暂时不能用!');
		window.close();
		</script>
<%		return;
	}
	String callbakcurl=request.getScheme()+"://"+request.getServerName()+"/jsp_cn/qq/callback.jsp";
	
	Map<String,String> tokenmap=QQ_Util.getAccessToken(authorization_Code,callbakcurl);
	if(tokenmap==null || !tokenmap.containsKey("accessToken")){
%>
		<script type="text/javascript">
			alert('QQ获取授权失败!');
			window.close();
		</script>
<%
		return;
	}
	String accessToken=tokenmap.get("accessToken");
	String openid=null;
	
	//对accessToken以及refreshToken进行保存
	if(accessToken!=null&&!accessToken.equals("")){
		CookieUtil.setCookieBean(response,QQ_Util.TXQQ_COOKIE_DATA_KEY+"_accessToken",accessToken);
		openid=QQ_Util.getOpenId(accessToken);
		
		if(openid!=null&&!openid.equals("")){
			CookieUtil.setCookieBean(response,QQ_Util.TXQQ_COOKIE_DATA_KEY+"_user",openid);
		}else{
			logger.warn("获取QQ openid 失败！");
		}
	}else{
		logger.warn("获取QQaccessToken失败！");
	}
	
	String docinpage = (String)session.getAttribute("docinpage_qq");
	if(page != null){
		session.setAttribute("docinpage_qq" , docinpage);
	}
		
	String url=(String)session.getAttribute("apppflag_qq");
	if(url==null){
		url="";
	}
	if(!"".equals(url)){
		session.setAttribute("apppflag_qq","1");
	}
	String from=(String)session.getAttribute("from");
	if(from!=null){
		session.setAttribute("from",from);
	}
	
	String forwardUrl=(String)session.getAttribute("url");
	if(forwardUrl!=null){
		session.setAttribute("url",forwardUrl);
	}
	
	String platform=(String)session.getAttribute("platform");
	if(platform==null){
		platform="";
	}
	response.sendRedirect("/conn/qq/login.do");
%>   